#include "foo.h"

char *matrix(char *a,int m,int n)
{
    int flag = 0;
    int num1 = 0, num2 = 1;
    int i = 0, j = 0;
    char s = 'A';
    *a=s;
    while(flag < m*n-1)
    {
        switch(num2%4)
        {
        case 1:
            ++j;
            if(j == n-num1-1)
            {
                num2++;
            }
            break;
        case 2:
            ++i;
            if(i == m-num1-1)
            {
                num2++;
            }
            break;
        case 3:
            --j;
            if(j == num1)
            {
                num2++;
            }
            break;
        case 0:
            --i;
            if(i == num1+1)
            {
                num2++;
                num1++;
            }
            break;
        }
        if(++s == 'Z'+1)
            s = 'A';
        *(a+i*n+j)=s;
        flag++;
    }
}
